import axios from "axios";

const baseUrl = '/api'
//axios二次封装
class HttpRequest{
    constructor(baseUrl){
        this.baseUrl = baseUrl
    }
    getInsideConfig(){
        const config = {
            baseUrl:this.baseUrl,
            header:{}
        }
        return config
    }
        //添加请求拦截器
        interceptors(instance){
            instance.interceptors.request.use(config => {
                return config
            },err => {
                return err
            })
            //响应拦截器
            instance.interceptors.response.use(res => {
                return res.data
            },err => {
                return err
            })
        }
    request(options){
        options = {...options,...this.getInsideConfig()}
        //创建axios实例
        const instance = axios.create()
        //实现拦截器的绑定
        this.interceptors(instance)
        return instance(options)

    }


}

export default new HttpRequest(baseUrl)